package rtp.servlets;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import rtp.model.*;
import rtp.model.dao.*;
import rtp.model.manager.*;

/**
 * Servlet implementation class ListarTarefasServlet
 */
@WebServlet("/ListarTarefasServlet")
public class ListarTarefasServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public ListarTarefasServlet() {
        // TODO Auto-generated constructor stub
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String s = request.getParameter("status");
		
		//TarefaExpert t = new TarefaExpert();
		//List<?> result = t.getTarefasPorStatus( s );
				
		String path = getServletContext().getInitParameter("Dados");
		//String path = "Tarefa/data/Dados.xml";
		ITarefaDAO dao = new TarefaDAO(path);
		TarefaManager manager = new TarefaManager(dao);
		ArrayList<Tarefa> result = manager.listarTarefas(s);
		
		//Tarefa tarefa = new Tarefa();
		
		//System.out.println("valor de testeenvioXML:"+testeenvioXML);
		//System.out.println("valor de result Size :"+result.size());
		//System.out.println("valor de result get0"+result.get(0).getDetalhes());
		
		
		
		request.setAttribute("tarefas", result);
		//request.setAttribute("goStatus", s);	
		//request.setAttribute("teste", testeenvioXML);
		
		RequestDispatcher view = null;
		if (s.contentEquals("A"))
			view = request.getRequestDispatcher("resulta.jsp");
		else if (s.contentEquals("F"))
			view = request.getRequestDispatcher("resultf.jsp");
		else
			view = request.getRequestDispatcher("listarTarefas.jsp");
		
		view.forward(request, response);
	}

}
